package com.glhtgyxy.biyesheji.Service;

import com.glhtgyxy.biyesheji.Mapper.houseMapper;
import com.glhtgyxy.biyesheji.Pojo.house;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;

@Service
public class houseService {

    @Autowired
    houseMapper mapper;

    public ArrayList<house> findAllHouse(){
        ArrayList<house> houses = mapper.findAllHouse();
        return houses;
    }

    public ArrayList<house> findmerchantHouse(int id){
        ArrayList<house> houses = mapper.findmerchantHouse(id);
        return houses;
    }


    public ArrayList<house> findHouse(String searchtext){
        ArrayList<house> houses = mapper.findHouse(searchtext);
        return houses;
    }


    public ArrayList<house> findmerchanthouseandtiaojian(
            String addr,
            String price,
            String bedroom,
            String search,
            String  id
    ){
        HashMap<String,String> map = new HashMap<>();
        if (!addr.equals("全部"))
        {
            map.put("addr",addr);
        }
        if (!price.equals("全部"))
        {
            if (price.contains("-"))
            {
                String[] split = price.split("-");
                map.put("pricelow",split[0]);
                map.put("priceheigh",split[1]);
            }else if (price.contains("以上"))
            {
                String[] split = price.split("以");
                map.put("pricelow",split[0]);
                map.put("priceheigh","99999");
            }else if (price.contains("以下"))
            {
                String[] split = price.split("以");
                map.put("pricelow","0");
                map.put("priceheigh",split[0]);
            }
        }
        if (!bedroom.equals("全部"))
        {
            map.put("bedroom",bedroom);
        }
        if (!search.equals("全部"))
        {
            map.put("search",search);
        }
        map.put("id",id);
        return  mapper.findmerchanthouseandtiaojian(map);
    }

    public boolean deleteHouse(int id){
        return mapper.deleteHouse(id)>0?true:false;
    }


}
